package Controller.reply;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import Bean.ReplyBean;
import Dao.ReplyDao;

public class singerBoardReplyController implements Controller{
	private ReplyDao dao;
	
	public void setDao(ReplyDao dao) {
		this.dao = dao;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest req,
			HttpServletResponse res) throws Exception {
		System.out.println("Reply 컨트롤러");
		String sr_context = req.getParameter("context");
		Integer sr_sb_no = Integer.parseInt(req.getParameter("sb_no"));
		
		System.out.println(sr_context);
		System.out.println(sr_sb_no);
		HttpSession session = req.getSession();
		String m_id = (String)session.getAttribute("member");
		System.out.println(m_id);
		ReplyBean rb = new ReplyBean();
		rb.setSr_context(sr_context);
		rb.setSr_sb_no(sr_sb_no);
		rb.setSr_m_id(m_id);
		
		dao.replyInsert(rb);
		System.out.println("리플 인서트 성공!!");
		int sr_no = 0;
		sr_no = dao.replyNewSelect(rb);
		System.out.println(sr_no);
		List<ReplyBean> newreply = dao.replyNewInsert(sr_no);
		System.out.println("새로운 리플 조회 성공!!");
		ModelAndView mav = new ModelAndView();
		mav.setViewName("sreply");
		mav.addObject("newreply", newreply);
		mav.addObject("sb_no", sr_sb_no);
		return mav;
	}

}
